function F=myfun(x,R1,T1,R1c,T1c)
%cost function for relative pose estimation 
Rici=quater2rot(x(1:4));
Tici=x(5:7)';
N=length(R1(:,1));
F=0;
for i=1:N
  q1=R1c(i,:);
  R=quater2rot(R1(i,:));
  q2=rot2quater(Rici*R*Rici');
  er=q1-q2;
  et=T1c(i,:)'+Rici*R*Rici'*Tici-Rici*T1(i,:)'-Tici;
  e=[er(:);et(:)];
  F=F+e'*e;
end

end

